<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
  <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
  <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	initParams();

});
//跳转到申请服务或投诉页面
function applyService(type){
	//投诉
	if("1"==type){
		window.location.href="${basePath}filemanagement/customer/complainPage.shtml";
	}else{
		window.location.href="${basePath}filemanagement/customer/applyServicePage.shtml";
	}
}
//删除客户服务
function deleteCustomerService(thisObj){
	 var pkCareformId=$(thisObj).attr("pkCareformId");
	 $.messager.confirm('温馨提示', '你确定要删除该项数据吗?', function(isOk) {
			if(isOk){
				$.ajax({
					url:"${basePath}filemanagement/customer/deleteCustomerService.shtml",
					dataType:"text",
					type:"post",
					async:false,
					data:{"pkCareformId":pkCareformId},
					error : function(XMLHttpRequest) {
      	 				ajaxError(XMLHttpRequest);
      	 			},
					success:function(result){
						if(result=="1"){
							alertInfo("删除成功!");
							initParams();
						}
					}
				});		
			}
	  });
}
//forward  to update
function updateComplaintPage(thisObj){
	 var pkCareformId=$(thisObj).attr("pkCareformId");
      window.location.href="${basePath}filemanagement/customer/updateComplaintPage.shtml?pkCareformId="+pkCareformId+"";
}
//read only info
function readComplainInfo(thisObj){
	 var pkCareformId=$(thisObj).attr("pkCareformId");
     window.location.href="${basePath}filemanagement/customer/readComplainInfo.shtml?pkCareformId="+pkCareformId+"";
}
//初始化参数
function initParams() {
	$("#pageNo").val("1");
	var myform = $("#serviceList");
	var pagebean = new PageBean(myform);
	pagebean.setTableId("showData");
	pagebean.setFootId("foot");
	pagebean.setCallback(showData);
	setPagebeanObj(pagebean); //全局化pageBean对象
	pagebean.doPage();  //执行分页
}
//展示数据
function showData(result){
	trimJsonArray(result);
	$(result).each(function(index,item){
		var 	obj2=item.workflowVo;
		var html="";
		html+=' <tr>_option_href</td>';
		html+='<td>'+item.createStartTime+'</td>';
		html+=' <td>'+item.userName+'</td>';
		html+='<td>_service_type</td>';
		html+='<td>_service_status</td>';
		html+='<td>_service_result</td>';
		html+='<td>'+item.cusName+'</td>';
       	html+='<td>'+item.mobile+'</td>';
       	if(item.comments.length>7){
       	 	html+='<td title="'+item.comments+'">'+item.comments.substring(0,7)+'...</td>';
       	}else{
       		html+='<td>'+item.comments+'</td>';
       	}
       	html+='<td>_service_option</td></tr>';
       	//逻辑判断
       	//投诉
       	if(item.careType=="1"){
       		html=html.replace('_service_type','投诉');
       		html=html.replace('_service_result','');
       		if(item.status=="1"){
       			//是否为当前用户发起的操作
       			if(item.workflowVo.isStartUser=="1"){
           			html=html.replace('_option_href','<td class="lv"><a href="#" onclick="updateComplaintPage(this);" pkCareformId="'+item.pkCareformId+'" >'+item.pkCareformId+'</a>');
           			html=html.replace('_service_option','<input type="button" onclick="updateComplaintPage(this);"  pkCareformId="'+item.pkCareformId+'"   value="编辑" class="btn_l"><input type="button" value="删除" pkCareformId="'+item.pkCareformId+'"   onclick="deleteCustomerService(this);"   class="btn_l ml10">');
       			}else{
           			html=html.replace('_option_href','<td>'+item.pkCareformId+'');
           			html=html.replace('_service_option','');
       			}
       			html=html.replace('_service_status','草稿');
       		}else{
       			html=html.replace('_option_href','<td class="lv"><a href="#" onclick="readComplainInfo(this);" pkCareformId="'+item.pkCareformId+'" >'+item.pkCareformId+'</a>');
       			html=html.replace('_service_status','完成');
       			html=html.replace('_service_option','');
       		}
       	}//申请
       	else{
       		html=html.replace('_service_type','申请');
       		if(item.status=="1"){
       			if(item.workflowVo.isStartUser=="1"){
           			html=html.replace('_option_href','<td class="lv"><a href="#" onclick="updateApplyService(this);"  pkCareformId="'+item.pkCareformId+'" >'+item.pkCareformId+'</a>');
           			html=html.replace('_service_option','<input type="button"   value="编辑"  onclick="updateApplyService(this);"  pkCareformId="'+item.pkCareformId+'"      class="btn_l"><input type="button" value="删除"  onclick="deleteCustomerService(this);"   pkCareformId="'+ item.pkCareformId+'"  class="btn_l ml10">');
       			}else{
       				html=html.replace('_option_href','<td>'+item.pkCareformId+'');
           			html=html.replace('_service_option','');
       			}       	
       			html=html.replace('_service_status','草稿');
           		html=html.replace('_service_result','');
       		}else if(item.status=="2"){
       			if(obj2.isCurrtOpt=="1"&&obj2.isStartUser=="1"){//退单  
       				html=html.replace('_option_href','<td class="lv"><a href="#"  pkCareformId="'+item.pkCareformId+'"   onclick="reApplyService(this);">'+item.pkCareformId+'</a>');
           			html=html.replace('_service_option','<input type="button"    pkCareformId="'+item.pkCareformId+'"   onclick="reApplyService(this);"    value="重新申请" class="btn_l">');
           			html=html.replace('_service_status','退单'); 
               		html=html.replace('_service_result','');
       			}else if(obj2.isCurrtOpt=="1"&&obj2.isStartUser=="0"){//处理人
       				html=html.replace('_option_href','<td class="lv"><a href="#" onclick="handleTheApplyService(this);"  pkCareformId="'+item.pkCareformId+'" >'+item.pkCareformId+'</a>');
           			html=html.replace('_service_option','<input type="button"  pkCareformId="'+item.pkCareformId+'"  onclick="handleTheApplyService(this);" value="处理"  class="btn_l">');
           			html=html.replace('_service_status','待处理');
               		html=html.replace('_service_result','');
       			}else{
       				html=html.replace('_option_href','<td class="lv"><a href="#" onclick="readInfo(this);"  pkCareformId="'+item.pkCareformId+'" >'+item.pkCareformId+'</a>');
           			html=html.replace('_service_option','');
           			html=html.replace('_service_status','待处理');
               		html=html.replace('_service_result','');
       			}
       		}else if(item.status=="3"){
       			html=html.replace('_option_href','<td class="lv"><a  href="#"  pkCareformId="'+item.pkCareformId+'"   onclick="readInfo(this);">'+item.pkCareformId+'</a>');
       			html=html.replace('_service_status',obj2.statusDesc);
       			html=html.replace('_service_result',obj2.result);
       			html=html.replace('_service_option','');
       		}else if(item.status=="4"){
       			html=html.replace('_option_href','<td class="lv"><a href="#"  pkCareformId="'+item.pkCareformId+'"   onclick="readInfo(this);">'+item.pkCareformId+'</a>');
       			html=html.replace('_service_status',obj2.statusDesc);
       			html=html.replace('_service_result',obj2.result);
       			html=html.replace('_service_option',''); 
       		}else if(item.status=="5"){
       			html=html.replace('_option_href','<td class="lv"><a  href="#"    pkCareformId="'+item.pkCareformId+'"   onclick="readInfo(this);">'+item.pkCareformId+'</a>');
       			html=html.replace('_service_status','关闭');
       			html=html.replace('_service_result','');
       			html=html.replace('_service_option','');  
       		}
       	}
		$("#showData").find("tr:eq("+index+")").after(html);
	});
}
//重新申请
function reApplyService(thisObj){
	var  pkCareformId=$(thisObj).attr("pkCareformId");
	window.location.href="${basePath}filemanagement/customer/reApplyService.shtml?pkCareformId="+pkCareformId+"";
}
//查询历史
function readInfo(thisObj){
	var pkCareformId=$(thisObj).attr("pkCareformId");
	window.location.href="${basePath}filemanagement/customer/readInfo.shtml?pkCareformId="+pkCareformId+"";
}
//处理提交的申请服务
function   handleTheApplyService(thisObj){
	var  pkCareformId=$(thisObj).attr("pkCareformId");
	window.location.href="${basePath}filemanagement/customer/handleServicePage.shtml?pkCareformId="+pkCareformId+"";
}
//编辑申请的服务..
function  updateApplyService(thisObj){
	var  pkCareformId=$(thisObj).attr("pkCareformId");
	window.location.href="${basePath}filemanagement/customer/updateAppService.shtml?pkCareformId="+pkCareformId+"";
}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    			<shiro:hasPermission name="filemanagement/listVip.shtml?type=1">
    						<li><a href="${basePath}filemanagement/listVip.shtml?type=1"><i class="nav_icon_b"></i><br>会员管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/viewVistors.shtml?type=3">
            			<li><a href="${basePath}filemanagement/viewVistors.shtml?type=3"><i class="nav_icon_d"></i><br>访客管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/listViewSingelTicket.shtml?type=2">
           				<li><a href="${basePath}filemanagement/listViewSingelTicket.shtml?type=2"><i class="nav_icon_a"></i><br>非会员管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="parreserve/parReserveManages.shtml?indexflag=">
					<li><a href="${basePath }parreserve/parReserveManages.shtml?indexflag="><i class="nav_icon_g"></i><br>预约管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/customer/serviceList.shtml">
						<li  class="content_hover"><a href="${basePath}filemanagement/customer/serviceList.shtml"><i class="nav_icon_h"></i><br>客户服务</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="crm/jumpCrm.shtml">
						<li><a href="${basePath }crm/jumpCrm.shtml"><i class="nav_icon_n"></i><br>客户关系管理</a></li>
    			</shiro:hasPermission>
			</ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
    		<form action="${basePath}filemanagement/customer/findServiceList.shtml" id="serviceList">
        		<input type="hidden" name="pageNo" id="pageNo" value="1">
    			<input type="hidden" name="pageSize" value="8">
        	<dl class="fixed" style="overflow:hidden">
            	<dd><label>类型：</label>
                	<div class="uboxstyle">
                        <select name="careType" id="careType">
                            <option value="">全部</option>
                            <option value="1">投诉</option>
                            <option value="2">申请</option>
                        </select>
                    </div>
                </dd>
                <dd><label>姓名/电话/备注：</label><input type="text" name="publicCondition" class="iput_t w200"></dd>
                <dd><label>创建时间：</label>                	<input title="" type="text" name="createStartTime" id="createStartTime"
					onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly /><span>至</span><input title="" type="text" name="createEndTime" id="createEndTime"
					onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly /></dd>
                <dd><label>状态：</label>
                	<div class="uboxstyle">
                        <select name="status" id="status">
                            <option value="">全部</option>
                            <option value="2">待处理</option>
                            <option value="1">草稿</option>
                            <option  value="4">退单</option>
                            <option value="3">完成</option>
                            <option value="5">关闭</option>
                        </select>
                    </div>
                </dd>
                <dd><label>所属门店：</label>
                    <div class="uboxstyle">
                        <select id="fkBranId" name="fkBranId">
                        	<c:if test="${fn:length(branList)>1}">
                            			<option value="">全部</option>
                            </c:if>
                            <c:forEach items="${branList}" var="item"  >
                            			<option value="${item.pkBranId}">${item.branName}</option>
                            </c:forEach>
                        </select>
                    </div>
                </dd>
            </dl>
           </form>
            <div>
                <input type="button" class="btn fr ml10" value="查询" onclick="initParams();"></div>
                <shiro:hasPermission name="service:createApplay">
                	                <input type="button" class="btn fr ml10" value="创建申请"  onclick="applyService('2');">
                </shiro:hasPermission>
                <shiro:hasPermission name="service:createComplain">
                					<input type="button" class="btn fr ml10" value="创建投诉"  onclick="applyService('1');" > 
                </shiro:hasPermission>
            </div>
        
        <div class="tab_normal mt10">
            <br/>
            <table class="table" id="showData">              
              <tr>
                  <th>服务请求</th>
                  <th>创建时间</th>
                  <th>创建人</th>
                  <th>类型</th>
                  <th>审批状态</th>
                  <th>审批结果</th>
                  <th>姓名</th>
                  <th>电话</th>
                  <th>备注</th>
                  <th>操作</th>
              </tr>
             
          </table>
          <!---翻页-->
          <div class="page fr m10" id="foot">
              
          </div>
    	</div>
        </div>
    </div>
</div>
</body>
</html>